package com.example.musicapi.dao;

import com.example.musicapi.entity.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface UserDao extends JpaRepository<User, String> {

    User findUserByName(String name);

    Page<User> findAll(Pageable pageable);

    Page<User> findAllByName(Pageable pageable, String name);

    //  根据 key 进行模糊查询的分页方法
    @Query("SELECT n FROM User n WHERE  n.name LIKE %:key%   ")
    Page<User> findBySearch(@Param("key") String key, Pageable pageable);

}
